﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Shapes;

namespace LogoScriptIDE
{
    /// <summary>
    /// FindWindow.xaml 的交互逻辑
    /// </summary>
    public partial class FindWindow : Window
    {
        /// <summary>
        /// 构造函数
        /// </summary>
        public FindWindow()
        {
            InitializeComponent();
        }

        /// <summary>
        /// 向上搜索按钮点击回调函数
        /// </summary>
        private void ui_searchUp_Click(object sender, RoutedEventArgs e)
        {
            ((MainWindow)Owner).FindPrevious(ui_text.Text, (bool)ui_case.IsChecked);
        }

        /// <summary>
        /// 向下搜索按钮点击回调函数
        /// </summary>
        private void ui_searchDown_Click(object sender, RoutedEventArgs e)
        {
            ((MainWindow)Owner).FindNext(ui_text.Text, (bool)ui_case.IsChecked);
        }

        /// <summary>
        /// 取消按钮点击回调函数
        /// </summary>
        private void ui_cancel_Click(object sender, RoutedEventArgs e)
        {
            Close();
        }

        /// <summary>
        /// 窗口关闭事件回调函数
        /// </summary>
        private void Window_Closing(object sender, System.ComponentModel.CancelEventArgs e)
        {
            //隐藏窗口，取消关闭事件
            Hide();
            Owner.Activate();
            e.Cancel = true;
        }

        /// <summary>
        /// 输入框输入回调函数
        /// </summary>
        private void ui_text_TextChanged(object sender, TextChangedEventArgs e)
        {
            // 如果输入框输入内容非空，那么允许搜素，否则不允许进行搜索
            if (ui_text.Text.Length == 0)
            {
                ui_searchUp.IsEnabled = false;
                ui_searchDown.IsEnabled = false;
            }
            else
            {
                ui_searchUp.IsEnabled = true;
                ui_searchDown.IsEnabled = true;
            }
        }
    }
}
